package com.pro.service.imple;

import com.pro.mapper.JsDeptManagementMapper;
import com.pro.pojo.JsDept;
import com.pro.pojo.JsDeptAuthority;
import com.pro.service.JsDeptManagementService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:JsDeptManagementServiceImple
 * Package:com.pro.service.imple
 * Description: 部门管理serviceImple
 *
 * @Date:2022/2/8 上午 9:04
 * @Author: WYH
 */
@Service
public class JsDeptManagementServiceImple implements JsDeptManagementService {

    @Autowired(required = false)
    private JsDeptManagementMapper jsDeptManagementMapper;

    @Autowired
    private RedisCache redisCache;


    /**
     * @Author WYH
     * @Description //TODO 查看所有部门信息
     * @Date 上午 9:06 2022/2/8
     * @Param deptName,trueName,createDate,status,limit,page
     * @return  List<JsDept>
     **/
    public List<JsDept> getJsDeptList(String deptName, String trueName, String createDate, String status, Integer limit, Integer page){
        page = (page - 1) * limit;
        List<JsDept> jsDeptList = jsDeptManagementMapper.getJsDeptList(deptName, trueName, createDate, status, limit, page);
        return jsDeptList;
    }

    /**
     * @Author WYH
     * @Description //TODO 计算所有部门信息个数
     * @Date 上午 9:07 2022/2/8
     * @Param deptName,trueName,createDate,status
     * @return  Integer
     **/
    public Integer countJsDeptList(String deptName,String trueName,String createDate,String status){
        Integer integer = jsDeptManagementMapper.countJsDeptList(deptName, trueName, createDate, status);
        return integer;
    }

    /**
     * @Author WYH
     * @Description //TODO 修改状态
     * @Date 上午 9:37 2022/2/9
     * @Param jsDept
     * @return  true | false
     **/
    public Boolean updateStatus(JsDept jsDept){
        Boolean updateStatus = jsDeptManagementMapper.updateStatus(jsDept);
        return updateStatus;
    }

    /**
     * @Author WYH
     * @Description //TODO 删除部门
     * @Date 上午 10:02 2022/2/9
     * @Param id
     * @return  true | false
     **/
    public Boolean deleteDept(Integer id){
        Boolean deleteDept = jsDeptManagementMapper.deleteDept(id);
        if (deleteDept){
            redisCache.deleteObject("dept");
        }
        return deleteDept;
    }

    /**
     * @Author WYH
     * @Description //TODO 根据id查询部门
     * @Date 上午 10:35 2022/2/9
     * @Param id
     * @return JsDept
     **/
    public JsDept getJsDeptById(Integer id){
        JsDept jsDeptById = jsDeptManagementMapper.getJsDeptById(id);
        return jsDeptById;
    }

    /**
     * @Author WYH
     * @Description //TODO 编辑部门
     * @Date 上午 10:42 2022/2/9
     * @Param jsDept
     * @return  true | false
     **/
    public Boolean updateJsDept(JsDept jsDept){
        Boolean updateJsDept = jsDeptManagementMapper.updateJsDept(jsDept);
        return updateJsDept;
    }

    /**
     * @Author WYH
     * @Description //TODO 添加部门
     * @Date 下午 3:05 2022/2/10
     * @Param jsDept | jsDeptAuthority
     * @return true | false
     **/
    public Boolean addJsDeptList(JsDept jsDept){
        Boolean addJsDeptList = jsDeptManagementMapper.addJsDeptList(jsDept);
        if (addJsDeptList){
            redisCache.deleteObject("dept");
        }
        return addJsDeptList;
    }
    public Boolean addJsDeptAuthority(JsDeptAuthority jsDeptAuthority){
        Boolean addJsDeptAuthority = jsDeptManagementMapper.addJsDeptAuthority(jsDeptAuthority);
        return addJsDeptAuthority;
    }
}
